home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Interprogram Messaging Manager / IPM MessageBoard / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-23  |  2.5 KB  |  164 lines  |  [TEXT/MPS ]

  1. /*-------------------------------------------------------------------------------------
  2.  *
  3.  * IPM MessageBoard AOCE Sample
  4.  *
  5.  * ©1992-1993 Apple Computer
  6.  *
  7.  -------------------------------------------------------------------------------------*/
  8. /*
  9.  * main.c -- main entry point and initialization
  10.  *
  11.  * change history:
  12.  *
  13.  * SJF        2/12/93        1.0b1        udpate to AOCE beta seed
  14.  * SJF        11/6/91        1.0d1        initial coding
  15.  *
  16.  */
  17.  
  18. #ifndef __TYPES__
  19. #include <Types.h>
  20. #endif
  21.  
  22. #ifndef __WINDOWS__
  23. #include <Windows.h>
  24. #endif
  25.  
  26. #ifndef __MENUS__
  27. #include <Menus.h>
  28. #endif
  29.  
  30. #ifndef __FONTS__
  31. #include <Fonts.h>
  32. #endif
  33.  
  34. #ifndef __OSEVENTS__
  35. #include <OSEvents.h>
  36. #endif
  37.  
  38.  
  39. #ifndef __TRAPS__
  40. #include <Traps.h>
  41. #endif
  42.  
  43. #ifndef __GESTALTEQU__
  44. #include <GestaltEqu.h>
  45. #endif
  46.  
  47. #ifndef __OCE__
  48. #include <OCE.h>
  49. #endif
  50.  
  51. #ifndef _GestaltDispatch
  52. #define    _GestaltDispatch    _Gestalt
  53. #endif
  54.  
  55. #include "const.h"
  56. #include "mymenus.h"
  57. #include "globals.h"
  58. #include "utils.h"
  59. #include "trapavailable.h"
  60. #include "myevents.h"
  61. #include "statusdialog.h"
  62. #include "myipm.h"
  63.  
  64. #include "main.h"
  65.  
  66. /* main entry point */
  67.  
  68. void main(void)
  69. {
  70.     InitQueues();
  71.  
  72.     if (DoError(InitToolboxes())==noErr && DoError(InitApplication())==noErr && HasAYS() && DoError(InitIPM())==noErr)
  73.         MainLoop();
  74.             
  75.     if (!HasAYS())
  76.         StopAlert(kNoAYSAlertID,nil);
  77.  
  78.     ExitProgram();
  79.     ExitToShell();
  80. }
  81.  
  82.  
  83. /* initializes the standard Mac toolbox */
  84.  
  85. OSErr InitToolboxes(void)
  86. {
  87.     MaxApplZone();
  88.     MoreMasters();
  89.     MoreMasters();
  90.     MoreMasters();
  91.     InitGraf(&qd.thePort);
  92.     InitFonts();
  93.     InitWindows();
  94.     InitMenus();
  95.     TEInit();
  96.     InitDialogs(nil);
  97.     InitCursor();
  98.     FlushEvents(everyEvent,0L);
  99.         
  100.     return noErr;
  101. }
  102.  
  103.  
  104. /* initializes the application globals/menus/windows/etc... */
  105.  
  106. OSErr InitApplication(void)
  107. {
  108.     // global variable initialization
  109.     
  110.     gHasWaitNextEvent = TrapAvailable(_WaitNextEvent);
  111.         
  112.     gDone = false;
  113.     gInBackground = false;
  114.     
  115.     InitMyMenus();
  116.     InitMyWindows();
  117.     
  118. //    gTypesList = &gAllTypes;
  119.     
  120.     return noErr;
  121. }
  122.  
  123.  
  124. void InitMyMenus(void)
  125. {
  126.     Handle mbar;
  127.     MenuHandle appleMenu;
  128.     
  129.     mbar = GetNewMBar(kMenuBarID);
  130.     SetMenuBar(mbar);
  131.     
  132.     appleMenu = GetMenu(kAppleMenu);
  133.     AddResMenu(appleMenu,'DRVR');            // build apple menu
  134.  
  135.     DrawMenuBar();
  136. }
  137.  
  138.  
  139. void InitMyWindows(void)
  140. {
  141.     MakeMainDialog();
  142. }
  143.  
  144.  
  145. // HasAYS
  146. //
  147. // returns true only of AYS is available and running
  148. //
  149. Boolean HasAYS(void)
  150. {
  151.     OSErr err;
  152.     long response;
  153.     
  154.     if (!TrapAvailable(_GestaltDispatch))
  155.         return false;
  156.     
  157.     err = Gestalt(gestaltOCEToolboxAttr,&response);
  158.     if (err!=noErr)
  159.         return false;
  160.         
  161.     return (response && (response << gestaltOCETBAvailable));
  162. }
  163.  
  164.